package com.wn.class30.service.impl;

import com.wn.class30.entity.AdminUser;
import com.wn.class30.entity.AdminUserExample;
import com.wn.class30.mapper.AdminUserDao;
import com.wn.class30.service.AdminUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: AdminUserServiceImpl 方法是
 * @author: jzy
 * @date: 2020/3/30 2:24 PM
 */
@Service
public class AdminUserServiceImpl implements AdminUserService{
    @Resource
    private AdminUserDao adminUserDao;

    public AdminUser selectAdminUserById(Integer id)throws Exception{
        return adminUserDao.selectByPrimaryKey(id);
    }

    @Override
    public List<AdminUser> selectAdminUsers() throws Exception {
        return adminUserDao.selectByExample(null);
    }

    @Override
    public AdminUser selectAdminUserByTel(String tel) throws Exception {
        AdminUserExample adminUserExample = new AdminUserExample();
        AdminUserExample.Criteria criteria = adminUserExample.createCriteria();
        criteria.andTelEqualTo(tel);
        List<AdminUser> adminUsers = adminUserDao.selectByExample(adminUserExample);
        if (adminUsers.size() > 0){
            return adminUsers.get(0);
        }
        return null;
    }


    @Override
    public void updateAdminUser(AdminUser adminUser) throws Exception {
        adminUserDao.updateByPrimaryKeySelective(adminUser);
    }

    @Override
    public void insertAdminUser(AdminUser adminUser) throws Exception {
        adminUserDao.insertSelective(adminUser);
    }

    @Override
    public AdminUser selectAdminUserByBusinessId(Integer businessId) throws Exception {
        AdminUserExample adminUserExample = new AdminUserExample();
        adminUserExample.createCriteria().andBusinessIdEqualTo(businessId);
        List<AdminUser> adminUsers = adminUserDao.selectByExample(adminUserExample);
        if (adminUsers.size() > 0){
            return adminUsers.get(0);
        }
        return null;
    }

    @Override
    public void deleteAdminUserByBusinessId(Integer businessId) throws Exception {
        AdminUserExample adminUserExample = new AdminUserExample();
        adminUserExample.createCriteria().andBusinessIdEqualTo(businessId);
        adminUserDao.deleteByExample(adminUserExample);
    }
}